﻿using System;
using System.Web.UI;
using Telerik.Web.UI;

public class AdminBaseUserControl : UserControl
{
    #region 脚本相关辅助方法
    /// <summary>
    /// 向页面添加脚本
    /// </summary>
    /// <param name="script">脚本</param>
    protected void AddScript(string script)
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), DateTime.Now.Ticks.ToString(), script, true);
    }

    /// <summary>
    /// 在页面中弹出消息框
    /// </summary>
    /// <param name="message">消息</param>
    protected void RadAlert(string message)
    {
        AddScript(string.Format("radalert('{0}', 280, 100);", message.Replace("'", "\'")));
    }

    /// <summary>
    /// 向页面添加脚本
    /// (使用RadAjaxManager情况下)
    /// </summary>
    /// <param name="script">脚本</param>
    protected void AddScriptM(string script)
    {
        RadAjaxManager.GetCurrent(Page).ResponseScripts.Add(script);
    }

    /// <summary>
    /// 在页面中弹出消息框
    /// (使用RadAjaxManager情况下)
    /// </summary>
    /// <param name="message">消息</param>
    protected void RadAlertM(string message)
    {
        AddScriptM(string.Format("radalert('{0}', 280, 100);", message.Replace("'", "\'")));
    }
    #endregion

    #region 当前用户
    private ltModel.Model.article_user currentUser;

    protected ltModel.Model.article_user CurrentUser
    {
        get
        {
            if (currentUser == null)
            {
                currentUser = DataCaches.GetUser(int.Parse(Page.User.Identity.Name));
            }
            return currentUser;
        }
    }

    private ltModel.Model.userTeam currentUserGroup;

    protected ltModel.Model.userTeam CurrentUserGroup
    {
        get
        {
            if (currentUserGroup == null)
            {
                currentUserGroup = DataCaches.GetUserTeam(CurrentUser.IsManager, CurrentUser.user_id);
            }
            return currentUserGroup;
        }
    }
    #endregion
}